var _timer = 30000;
var _split = 1;
var _id = 0;

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var c_numbers = ["","1 尾","2 尾","3 尾","4 尾","5 尾","6 尾","7 尾","8 尾","9 尾","0 尾"];
var c_chinayear = ["","鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;
var chkbutmod = false;
var b211_num = 0;
var b212_num = 0;
var b213_num = "";
var b221_num = 0;
var b222_num = 0;
var b223_num = "";
var b341_num = 0;
var b342_num = 0;
var b343_num = "";
var b351_num = 0;
var b352_num = 0;
var b353_num = "";
var account1 = "";
var account2 = "";
var account3 = "";
var account4 = "";

var timer_id;
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=unow7&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	show_rate21(a[0]);
	show_rate22(a[1]);
	show_titleAmu(a[2]);
	window.status = "";
}

function show_rate21(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["num21_"+i].innerHTML = _name21[i];
		document.all["rate21_"+i].innerHTML = rate;
		document.all["amount21_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=1006&numbers="+i+">"+Math.floor(amount)+"</a>";
		document.all["chg21_"+i].innerHTML = "<input type=checkbox id=rrr21_"+d2(i)+" onclick=\"quickrrr(21, "+i+")\">";
		win1 = Math.floor(win - a00[3]);
		document.all["win21_"+i].innerHTML = win1;
		document.all["win21_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function gen_rate21()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb21head;
	ret += "</tr>";
	
	for (j=0; j<6; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num21_"+k+" class=td6 align=center></td><td nowrap id=amount21_"+k+"></td><td nowrap id=win21_"+k+"></td><td id=rate21_"+k+" class=rate></td><td align=center id=chg21_"+k+"></td>";
		}
		ret += "</tr>";
	}
	ret += "</table>";
	document.all.div21.innerHTML = ret;
}

function show_rate22(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<11; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		document.all["num22_"+i].innerHTML = _name22[i];
		document.all["rate22_"+i].innerHTML = rate;
		document.all["amount22_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=1007&numbers="+i+">"+Math.floor(amount)+"</a>";
		document.all["chg22_"+i].innerHTML = "<input type=checkbox id=rrr22_"+d2(i)+" onclick=\"quickrrr(22, "+i+")\">";
		win1 = Math.floor(win - a00[3]);
		document.all["win22_"+i].innerHTML = win1;
		document.all["win22_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function gen_rate22()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb22head;
	ret += "</tr>";
	
	for (j=0; j<5; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num22_"+k+" class=td6 align=center></td><td nowrap id=amount22_"+k+"></td><td nowrap id=win22_"+k+"></td><td id=rate22_"+k+" class=rate></td><td align=center id=chg22_"+k+"></td>";
		}
		ret += "</tr>";
	}
	ret += "</table>";
	document.all.div22.innerHTML = ret;
}


function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}

function quickrrr(c, i)
{
	if (document.all["rrr"+c+"_"+d2(i)].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
	}
}

function protect_b1()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b211_num = document.all.b211.value-0;
	b212_num = document.all.b212.value-0;
	b213_num = document.all.b213.value-0;
	account1 = document.all.usr1.value;
	if (b211_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b211_num > 3) {
		alert("不合理的赔率数值！");
	} else if (b212_num > 6) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b211", document.all.b211.value);
		SetCookie("b212", document.all.b212.value);
		if (b213_num > 0) {
			for (i=1; i<13; i++) {
				if (document.all["rrr21_"+d2(i)].checked) {
					//if (document.all["amount21_"+i].innerHTML-0 >= b213_num) {
						_bet[count] = 21;
						_num[count] = i;
						cc += "生肖 "+c_chinayear[i]+"  →  "+b213_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("七码生肖走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b211_num+"&back="+b212_num+"&nts="+b213_num+"&acc="+account1, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成");
				}
			}
		}
	}
	b213_num = "";
	document.all.b213.value = b213_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b2()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b221_num = document.all.b221.value-0;
	b222_num = document.all.b222.value-0;
	b223_num = document.all.b223.value-0;
	account2 = document.all.usr2.value;
	if (b221_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b221_num > 3) {
		alert("不合理的赔率数值！");
	} else if (b222_num > 6) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b221", document.all.b221.value);
		SetCookie("b222", document.all.b222.value);
		if (b223_num > 0) {
			for (i=1; i<11; i++) {
				if (document.all["rrr22_"+d2(i)].checked) {
					//if (document.all["amount22_"+i].innerHTML-0 >= b223_num) {
						_bet[count] = 22;
						_num[count] = i;
						cc += "尾数 "+c_numbers[i]+"  →  "+b223_num+"\n";
						count++;
					//}
				}
			}
			if (count > 0) {
				if (confirm("七码尾数走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b221_num+"&back="+b222_num+"&nts="+b223_num+"&acc="+account2, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成");
				}
			}
		}
	}
	b223_num = "";
	document.all.b223.value = b223_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b3()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b341_num = document.all.b341.value-0;
	b342_num = document.all.b342.value-0;
	b343_num = document.all.b343.value-0;
	account3 = document.all.usr3.value;
	if (b341_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b341_num > 22) {
		alert("不合理的赔率数值！");
	} else if (b342_num > 15) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b341", document.all.b341.value);
		SetCookie("b342", document.all.b342.value);
		if (b343_num > 0) {
			for (i=1; i<5; i++) {
				if (document.all["rrr34_"+d2(i)].checked) {
					_bet[count] = 34;
					_num[count] = i+3;
					cc += _name34[i]+"  →  "+b343_num+"\n";
					count++;
				}
			}
			if (count > 0) {
				if (confirm("总肖走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b341_num+"&back="+b342_num+"&nts="+b343_num+"&acc="+account3, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成！");
				}
			}
		}
	}
	b343_num = "";
	document.all.b343.value = b343_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b4()
{
	var cc = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	b351_num = document.all.b351.value-0;
	b352_num = document.all.b352.value-0;
	b353_num = document.all.b353.value-0;
	account4 = document.all.usr4.value;
	if (b351_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b351_num > 3.8) {
		alert("不合理的赔率数值！");
	} else if (b352_num > 15) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b351", document.all.b351.value);
		SetCookie("b352", document.all.b352.value);
		if (b353_num > 0) {
			for (i=1; i<3; i++) {
				if (document.all["rrr35_"+d2(i)].checked) {
					_bet[count] = 35;
					_num[count] = i;
					cc += _name35[i]+"  →  "+b353_num+"\n";
					count++;
				}
			}
			if (count > 0) {
				if (confirm("总肖单双走飞内容\n—————————  \n"+cc+"—————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves&id="+_id+"&bt="+_bet+"&num="+_num+"&rate="+b351_num+"&back="+b352_num+"&nts="+b353_num+"&acc="+account4, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成！");
				}
			}
		}
	}
	b353_num = "";
	document.all.b353.value = b353_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate21();
	gen_rate22();
	b211_num = document.all.b211.value-0.00;
	b212_num = document.all.b212.value-0.00;
	b213_num = document.all.b213.value-0;
	account1 = document.all.usr1.value;
	b221_num = document.all.b221.value-0.00;
	b222_num = document.all.b222.value-0.00;
	b223_num = document.all.b223.value-0;
	account2 = document.all.usr2.value;
	chkbutmod = false;
	timer();
}

window.onload = winonload;